#pragma once

#include "HashTable.h"

namespace yyq
{
	template<class K, class Hash = HashFunc<K>>
	class unorder_set
	{
		struct SetKeyOfValue
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename buckethash::HashTable<K, K, SetKeyOfValue, Hash>::iterator iterator;
		
		iterator begin()
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}

		std::pair<iterator, bool> insert(const K& key)
		{
			return _ht.Insert(key);
		}

		iterator find(const K& key)
		{
			return _ht.Find(key);
		}

		bool erase(const K& key)
		{
			return _ht.Erase(key);
		}

	private:
		buckethash::HashTable<K, K, SetKeyOfValue, Hash> _ht;
	};

	void test1_unorder_set()
	{
		yyq::unorder_set<int> us;
		us.insert(2);
		us.insert(15);
		us.insert(41);
		us.insert(12);
		us.insert(6);
		us.insert(8);
		us.insert(9);
		us.insert(26);
		us.insert(11);
		us.insert(5);

		yyq::unorder_set<int>::iterator it = us.begin();
		while (it != us.end())
		{
			std::cout << *it << " ";
			++it;			
		}
		std::cout << std::endl;
	}
}
